package likou;

/**
 * @author: Tangxz
 * @email: 1171702529@qq.com
 * @cate: 2020/11/18 07:51
 */
public class _328 {
    public static void main(String[] args) {

    }

    public static ListNode oddEvenList(ListNode head) {
        if (head == null || head.next == null) {
            return head;
        }
        //偶数下标，需要一个头节点
        //需要两个结点来操作下标
        ListNode evenHead = head.next;
        ListNode odd = head, even = evenHead;
        while (even != null && even.next != null) {
            odd.next = even.next;
            odd = odd.next;
            even.next = odd.next;
            even = even.next;
        }
        odd.next = evenHead;
        return head;


//        if (head == null) {
//            return head;
//        }
//        ListNode evenHead = head.next;
//        ListNode odd = head, even = evenHead;
//        while (even != null && even.next != null) {
//            odd.next = even.next;
//            odd = odd.next;
//            even.next = odd.next;
//            even = even.next;
//        }
//        odd.next = evenHead;
//        return head;
    }
}
